﻿<!DOCTYPE html>
<!--承包商入场工具管理销核-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="140px"
            size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <!--type="text" v-model="Form.ContractorName" autocomplete="off"-->
                                <template slot="prepend">
                                    {{ContractorAdmissionTool.ContractorName+mark.m}}
                                </template>
                                <el-select @visible-change="visibleChange" v-model="CBSListId" slot="suffix" @change="postChange" style="margin-left: 150px;">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in CBS_Lists" :label="item.contractorName"
                                               :value="item.id"></el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.headUser" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorAdmissionTool.PersonnelName+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.phone" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorAdmissionTool.phone+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

            </el-row>
            <el-row>
                <el-col span="24">
                    <el-table stripe :data="Form.ToolList" border>
                        <el-table-column prop="carryingToolName" :label="ContractorAdmissionTool.CarryingToolName">
                        </el-table-column>

                        <el-table-column prop="carryingToolQuantity" :label="ContractorAdmissionTool.InCarryingQuantity">
                        </el-table-column>
                        <!--<el-table-column prop="IsConsumables" :label="ContractorAdmissionTool.IsConsumables">
    </el-table-column>-->
                        <!--prop="OutCarryingQuantity"-->
                        <el-table-column prop="mark03"
                                         :label="ContractorAdmissionTool.OutCarryingQuantity">
                            <template slot-scope="scope">
                                <a style="color:blue" @click=PinCorehistory('xg',scope.row.id)>
                                    {{scope.row.mark03}}
                                </a>
                            </template>
                        </el-table-column>

                        <el-table-column :label="ContractorAdmissionTool.ThisOutCarryingQuantity" width="180px">
                            <template slot-scope="scope">
                                <el-input-number v-model="scope.row.ThisOutCarryingQuantity" @change="handleChange"
                                                 :min="0" size="mini"></el-input-number>
                            </template>
                        </el-table-column>
                        

                        <!-- <el-table-column :label="ContractorAdmissionTool.SituationStatement" width="180px">
        <template slot-scope="scope">
            <button type="button" class="elst-bt-xg" @click=PinCore('xg',scope.row.id)>
                <i class="el-icon-edit"></i>
            </button>
        </template>
    </el-table-column> -->
                        <el-table-column prop="SituationStatement" :label="ContractorAdmissionTool.SituationStatement">
                            <template slot-scope="scope">
                                <el-input type="text" v-model="scope.row.SituationStatement" size="mini"></el-input>
                            </template>
                        </el-table-column>


                    </el-table>
                </el-col>
            </el-row>
            <br>

            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnPinCore}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <el-dialog :title="title" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog'
            width="80%" height="80%" top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                title: '',
                ListItem: ListItem,
                CBS_Lists: [],
                CBSListId: null,
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    headUser: '',//姓名
                    phone: '',//电话号
                    ContractorName: '',//承包商名称
                    cbs_OutFactoryTool: [],
                    ToolList: []//携带工具名称

                },
                IsConsumables: [],

                //表单验证
                rules: {
                    PersonnelName: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(2, 5), message: verification.StringLengthAtoB.m.format(2, 5), trigger: 'blur' }
                    ],
                    ContractorName: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(5, 50), message: verification.StringLengthAtoB.m.format(5, 10), trigger: 'blur' }
                    ]
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                handleChange: function (value) {
                    console.log(value);
                },
                handleChangeA: function (value) {
                    console.log(value);
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            //onSubmitForm(this, '/api/CBS_IntoFactoryTool/Save', mythis.Form);
                            for (var i = 0; i < mythis.Form.ToolList.length; i++) {
                                //mythis.Form.ToolList[i].id = mythis.Form.CBSListId;
                                //mythis.Form.ToolList[i].intoFactoryToolId = mythis.Form.ToolList[i].id;
                                //mythis.Form.ToolList[i].SituationStatement
                                //mythis.Form.ToolList[i].ThisOutCarryingQuantity
                                mythis.Form.ToolList[i].mark02 = parseInt(mythis.Form.ToolList[i].mark03) + parseInt(mythis.Form.ToolList[i].ThisOutCarryingQuantity);
                                if (parseInt(mythis.Form.ToolList[i].mark02) > parseInt(mythis.Form.ToolList[i].carryingToolQuantity)) {
                                    alert('出场工具数量不正确！');
                                    return;
                                } else {
                                    onSubmitForm(this, '/api/CBS_OutFactoryTool/Save', { intoFactoryToolId: mythis.Form.ToolList[i].id, SituationStatement: mythis.Form.ToolList[i].SituationStatement, OutCarryingQuantity: mythis.Form.ToolList[i].ThisOutCarryingQuantity });//核销历史
                                    onSubmitForm(this, '/api/CBS_IntoFactoryTool/Save', mythis.Form.ToolList[i]);
                                }
                            }
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    //getData(this, '/api/CBS_IntoFactoryTool/get?id=' + this.id);
                    var mythis = this;
                    if (mythis.id != null && mythis.id != '') {
                        myAjax("get", mythis, '/api/CBS_IntoFactoryTool/get?id=' + this.id, null, function (response) {
                            var ajaxModel = response.data;
                            mythis.Form = ajaxModel;
                            mythis.CBSListId = ajaxModel.cbsListId;

                            //console.log('h1', response.data.pageData);
                            myAjax("post", this, '/api/CBS_IntoFactoryTool/GetList', { model: { cbsListId: ajaxModel.cbsListId, headUser: ajaxModel.headUser, phone: ajaxModel.phone, arrivalTime: ajaxModel.arrivalTime, admissionConfirmer: ajaxModel.admissionConfirmer }, offset: 0, limit: 100 }, function (response) {
                                var ToolList = response.data.pageData;
                                for (var i = 0; i < ToolList.length; i++) {
                                    var ocqTemp = 0;
                                    var tlModel = ToolList[i];
                                    for (var j = 0; j < tlModel.cbS_OutFactoryTool.length; j++) {
                                        ocqTemp = parseInt(ocqTemp) + tlModel.cbS_OutFactoryTool[j].outCarryingQuantity;
                                    }
                                    ToolList[i].mark03 = ocqTemp;
                                    ToolList[i].ThisOutCarryingQuantity = 0;
                                }
                                mythis.Form.ToolList = ToolList;
                                //console.log('h1', response.data.pageData);
                            }, false);



                            //mythis.userFrom.sex = mythis.userFrom.sex + "";
                        }, false);
                    }
                },
                PinCore: function (val, id) {
                    this.title = "情况说明";
                    DialogShow(this, val, "ContractorToolPinCoreSituation.html", id);
                },
                PinCorehistory: function (val, id) {
                    this.title = "销核历史纪录";
                    DialogShow(this, val, "ContractorAdmissionToolPinCorehistory.html", id);
                },
                //初始化承包商下拉框
                getCBS_List: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/CBS_List/GetList', { model: { status: '', CreateFactory: null }, offset: 0, limit: 100 }, function (response) {
                        mythis.CBS_Lists = response.data.pageData;
                        //console.log('h1', response.data.pageData);
                    }, false);
                }, postChange: function (val) {
                    //初始化承包商选项
                    if (this.id == null) {
                        this.CBS_UserLists = [];
                    }
                    this.CBSListId = val;

                },
                GetPageData: function () { }
            },
            mounted: function () {
                //this.IsConsumables = getDicData('50');
                this.id = getUrlParam("id");
                this.getCBS_List();
                this.getData();
            }
        });
    </script>
</body>

</html>